package demo

import (
	"context"
	"log"

	"github.com/ClickHouse/clickhouse-go/v2/lib/driver"
)

type ProtocolType string

const (
	HTTP     ProtocolType = "http"
	FTP      ProtocolType = "ftp"
	SMB      ProtocolType = "smb"
	NFS      ProtocolType = "nfs"
	TFTP     ProtocolType = "tftp"
	SCP      ProtocolType = "scp"
	RSync    ProtocolType = "rsync"
	Database ProtocolType = "database"
)

func insertEnum8(conn driver.Conn) error {
	// 插入枚举数据
	return conn.Exec(context.Background(), "INSERT INTO network_logs (protocol) VALUES (?)", string(HTTP))
}

func queryEnum8(conn driver.Conn) error {
	// 查询Enum8字段
	rows, err := conn.Query(context.Background(), "SELECT protocol FROM network_logs")
	if err != nil {
		log.Fatal(err)
	}
	defer rows.Close()

	// 处理结果
	for rows.Next() {
		var protocol string
		err := rows.Scan(&protocol)
		if err != nil {
			log.Fatal(err)
		}
		log.Printf("Protocol: %v", protocol)
	}

	return nil
}

func RunEnum8Demo(conn driver.Conn) {
	// 插入枚举数据
	err := insertEnum8(conn)
	if err != nil {
		log.Fatal(err)
	}

	// 查询Enum8字段
	queryEnum8(conn)
}
